package my.demo.controller;

import my.demo.service.WXService;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@RestController
@RequestMapping("wx")
public class WXController {
    private WXService wxService;
    public WXController(WXService wxService) {
        this.wxService = wxService;
    }
    @GetMapping("applet/login")
    public String appletLogin(@RequestParam String code) {
        wxService.getAppletOpenid(code);
        return "已获取到用户的openid";
    }

    @PostMapping("applet/send")
    public String appletSend() {
        wxService.appletSendMessage();
        return "已发送";
    }

    @GetMapping("official/auth")
    public void officialAuth(HttpServletResponse response) {
        wxService.officialAuth(response);
    }

    @RequestMapping("official/login")
    public void officialLogin(@RequestParam Map<String, Object> params) {
        wxService.officialLogin(params);
    }

    @RequestMapping("official/send")
    public void officialSend(@RequestParam Map<String, Object> params) {
        wxService.getOfficialOpenid(params);
    }

    @PostMapping("official/send")
    public String officialSend() {
        wxService.officialSendMessage();
        return "已发送";
    }

    @PostMapping("official/template/send")
    public String officialTemplateSend() {
        wxService.officialTemplateSend();
        return "已发送";
    }

    @GetMapping(value = "official/router")
    public void officialRouter(HttpServletResponse response) {
        wxService.officialRouter(response);
    }
}
